package com.tzstcl.sys.user;

import com.alibaba.fastjson.JSON;
import com.tzstcl.commons.utils.StringUtils;
import com.tzstcl.sys.user.model.SysMenu;
import com.tzstcl.sys.user.model.WTTMenu;

import java.util.ArrayList;
import java.util.List;

/**
 * 公司：天筑科技股份有限公司
 * 作者：zgq
 * 日期：2018年12月28日
 * 说明：
 */
public class WTTMenuUtil {

    public static String getWttMenusString(List<SysMenu> sysMenuList) {
        return JSON.toJSONString(getChildren(0L, sysMenuList));
    }

    /**
     * @param menuId      福彩的id
     * @param sysMenuList 菜单列表
     * @return
     */
    public static List<WTTMenu> getChildren(Long menuId, List<SysMenu> sysMenuList) {
        List<WTTMenu> wttMenuList = new ArrayList<>();
        if (null == menuId || null == sysMenuList || sysMenuList.size() == 0) {
            return wttMenuList;
        }
        if (0==menuId) {      //顶层菜单
            for (SysMenu menu : sysMenuList) {
                if (0==menu.getParentId()) {
                    WTTMenu wttMenu = new WTTMenu();
//                    wttMenu.setId(menu.getId());
                    wttMenu.setText(menu.getName());
                    wttMenu.setIcon(menu.getIcon());
                    wttMenu.setUrl(menu.getHref());
                    wttMenu.setTargetType("iframe-tab");
                    wttMenu.setUrlType("abosulte");
                    wttMenu.setChildren(getChildren(menu.getId(), sysMenuList));
                    wttMenuList.add(wttMenu);
                }
            }
        } else { //子菜单
            for (SysMenu menu : sysMenuList) {
                if (menuId.equals(menu.getParentId()) ) {
                    WTTMenu wttMenu = new WTTMenu();
                    wttMenu.setId(menu.getId());
                    wttMenu.setText(menu.getName());
                    wttMenu.setIcon(menu.getIcon());
                    wttMenu.setUrl(menu.getHref());
                    wttMenu.setTargetType("iframe-tab");
                    wttMenu.setUrlType("abosulte");
                    wttMenu.setChildren(getChildren(menu.getId(), sysMenuList));
                    wttMenuList.add(wttMenu);
                }
            }
        }
        return wttMenuList;

    }
}
